package com.bwie.record.consumer;

import com.alibaba.fastjson.JSON;
import com.bwie.record.domain.DataThree;
import com.bwie.record.service.DataThreeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class DataConsumer3 {
    @Autowired
    private DataThreeService dataThreeService;

    @RabbitListener(queues = "dataThreeQueue")
    public void consumeDataThree(String dataThree) {
        DataThree data = JSON.parseObject(dataThree, DataThree.class);
        log.info("消费者3接收到数据： " + data +", 时间："+ new Date().toLocaleString());

        DataThree dataThreeInfo = dataThreeService.getDataThreeById(data.getId());
        if (dataThreeInfo == null) {
            dataThreeService.addDataThree(data);
        } else {
            dataThreeService.updateDataThree(data);
        }
    }
}
